﻿using System.Data.Entity.ModelConfiguration;

namespace JHT.EFMigrationTest.ClassLibrary1
{
    internal class TeacherInfoMap : EntityTypeConfiguration<TeacherInfo>
    {
        public TeacherInfoMap()
        {
            ToTable("TeacherInfo");
            HasKey(p => p.Id);// 设置主键
            Property(p => p.Id)// 设置字段
                .HasColumnName("Id")//设置字段名
                .HasColumnType("bigint")//设置字段类别
                .HasDatabaseGeneratedOption(System.ComponentModel.DataAnnotations.Schema.DatabaseGeneratedOption.Identity)//数据库生成操作
                .IsRequired();// 是否为必须

            Property(p => p.TeacherName).HasColumnName("TeacherName").HasColumnType("varchar").IsRequired().HasMaxLength(50);
            Property(p => p.TeacherType).HasColumnName("TeacherType").HasColumnType("int").IsOptional();
            Property(p => p.ComlextType.Nation).HasColumnName("Nation").HasColumnType("varchar").HasMaxLength(50).IsOptional();
            
            HasMany(p => p.ClassInfos).WithMany(c => c.Teachers).Map(cs =>
            {
                cs.MapLeftKey("TeacherId");
                cs.MapRightKey("ClassInfoId");
                cs.ToTable("TeacherClass");
            });
        }
    }
}